package zb.service.imp;

import org.springframework.stereotype.Service;
import zb.pojo.Order;
import zb.pojo.User;
import zb.feign.OrderfeignClient;
import zb.feign.OrderitemfeignClient;
import zb.service.Userservice;

import javax.annotation.Resource;
import java.util.List;

@Service
public class Userserviceimp implements Userservice {
    @Resource
     OrderfeignClient orderfeignClient;
    @Resource
    OrderitemfeignClient orderitemfeignClient;
    @Override
    public User findUserById(Integer uid) throws Exception{
        User user=new User();
        user.setId(uid);
        user.setName(Math.random()+"");

        //通过feign来远程调用

        List<Order> orders = orderfeignClient.ShowUserOrder(uid);
        user.setOrders(orders);
//        String str=orderitemfeignClient.itemInfo();
//        System.out.println(str);
        return user;

    }

    @Override
    public Integer UserAddOrder(Order order) {
       //远程调用

        Integer num=
                orderfeignClient.saveOrder(order);
        return num;
    }

    @Override
    public User showUser(String name) {
        //登录
        User user=new User();
        if("admin".equals(name)){
            user.setId(1);
            user.setName("admin");
        }
        return user;
    }


}
